package AionCrafter.ui;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

import javax.swing.table.AbstractTableModel;

import AionCrafter.AionCrafterApplication;
import AionCrafter.data.Recipe;

/**
 * Table Columns are: Craft Level, Recipe Name, Recipe ID (invisible)
 */
public class RecipeTableModel extends AbstractTableModel {
	private String[] columnNames = {"Lvl","Recipe Name"}; 
    private ArrayList<Object[]> data = new ArrayList<Object[]>();
    
    Map<String,Recipe> recipeMap;

	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public int getRowCount() {
		return data.size();
	}

	@Override
	public Object getValueAt(int row, int col) {
		return data.get(row)[col];
	}
	
	@Override
	public String getColumnName(int col) {
        return columnNames[col];
    }
	
	public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
	
	public void changeMode(int mode){
		switch(mode){
		case 1: recipeMap = AionCrafterApplication.alchemyList.getRecipes(); break;
		case 2: recipeMap = AionCrafterApplication.armorList.getRecipes(); break;
		case 3: recipeMap = AionCrafterApplication.cookingList.getRecipes(); break;
		case 4: recipeMap = AionCrafterApplication.handicraftList.getRecipes(); break;
		case 5: recipeMap = AionCrafterApplication.tailorList.getRecipes(); break;
		case 6: recipeMap = AionCrafterApplication.weaponList.getRecipes(); break;
		}
		data.clear();
		Iterator itr = recipeMap.entrySet().iterator();
		while(itr.hasNext()){
			Map.Entry pair = (Map.Entry) itr.next();
			Object[] nextRecipe = {((Recipe)pair.getValue()).getLevel(),
					((Recipe)pair.getValue()).getName(),
					pair.getKey()};
			data.add(nextRecipe);
		}
	}
}
